package com.javasm.service.impl;

import com.javasm.dao.RoomDao;
import com.javasm.entity.Room;
import com.javasm.service.RoomService;
import com.javasm.utils.MyBatisHeapler;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class RoomServiceImpl implements RoomService {

    @Override
    public Integer addPlyRoom(Room inputRoom) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        RoomDao mapper = sqlSession.getMapper(RoomDao.class);
        Integer resNum = mapper.addPlyRoom(inputRoom);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return resNum;
    }
    @Override
    public Integer countPlyRooms(Room inputRoom) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        RoomDao mapper = sqlSession.getMapper(RoomDao.class);
        Integer resNum = mapper.countPlyRooms(inputRoom);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return resNum;
    }
    @Override
    public Integer deletePlyRoomById(Integer roomId) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        RoomDao mapper = sqlSession.getMapper(RoomDao.class);
        Integer resNum = mapper.deletePlyRoomById(roomId);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return resNum;
    }
    @Override
    public Integer editPlyRoom(Room inputRoom) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        RoomDao mapper = sqlSession.getMapper(RoomDao.class);
        Integer resNum = mapper.editPlyRoom(inputRoom);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return resNum;
    }
    @Override
    public Integer editPlyRoomStauts(Room inputRoom) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        RoomDao mapper = sqlSession.getMapper(RoomDao.class);
        Integer resNum = mapper.editPlyRoomStauts(inputRoom);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return resNum;
    }
    @Override
    public Room getPlyRoomById(Integer roomId) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        RoomDao mapper = sqlSession.getMapper(RoomDao.class);
        Room resNum = mapper.getPlyRoomById(roomId);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return resNum;
    }
    @Override
    public List<Room> listPlyRooms(Room inputRoom, Integer page, Integer pageSize) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        RoomDao roomDao = sqlSession.getMapper(RoomDao.class);
        List<Room> listRoom = roomDao.listPlyRooms(inputRoom,(page-1)*pageSize,pageSize);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return listRoom;
    }


}
